package com.brsya.movie.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.brsya.base.bean.MovieBean;
import com.brsya.base.recycler.BaseAdapter;
import com.brsya.base.recycler.BaseViewHolder;
import com.brsya.base.util.GlideUtil;
import com.brsya.movie.R;

/**
 * Created by Brsya
 * CreateDate: 2022/7/7  16:10
 * Description:
 * 搜索历史
 */
public class SearchHistoryAdapter extends BaseAdapter<MovieBean> {

    private final Context context;

    public SearchHistoryAdapter(Context context) {
        this.context = context;
    }

    @Override
    public BaseViewHolder onCreate(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(context).inflate(R.layout.item_search_history, parent, false);
        return new BaseViewHolder(rootView);
    }

    @Override
    public void onBind(BaseViewHolder viewHolder, int RealPosition, MovieBean data) {
        View vStart = viewHolder.findViewById(R.id.v_start);
        ImageView ivMovieImg = viewHolder.findViewById(R.id.iv_movie_img);
        TextView tvMovieName = viewHolder.findViewById(R.id.tv_movie_name);
        View vEnd = viewHolder.findViewById(R.id.v_end);

        if (RealPosition == 0) {
            vStart.setVisibility(View.VISIBLE);
        } else if (RealPosition == getDataList().size() - 1) {
            vEnd.setVisibility(View.VISIBLE);
        } else {
            vStart.setVisibility(View.GONE);
            vEnd.setVisibility(View.GONE);
        }

        GlideUtil.loadRound(ivMovieImg, data.getCoverUrl(), 6);

        tvMovieName.setText(data.getName());

    }

}
